//------------------------------------------------
//		PWM1.c
//	PWM library
//	Arthur Benemann 19/12/2011
//------------------------------------------------
//	Description:
//FIXME
//-----------------------------------------------
//	Requeriments:
//	OCx
//	1 Remapable pin (PWM out)
//-----------------------------------------------

#include "picDev.h"

#define SYS_CLK	0x7
#define EDGE_PWM	0x6	//Center-aligned PWM mode 
#define CENTER_PWM	0x7 //Edge-aligned PWM Mode 

//----------------------------------------------
void initPWM1(unsigned int period,unsigned int duty)
{
	PWM1_OUT= Ro_OC1;

	OC1R  = duty;				// Duty cycle
	OC1RS = period; 			// Period

	OC1CON2bits.SYNCSEL = 0x1f;	// No external sync
	OC1CON2bits.OCTRIG  = 0x00;	// 
	OC1CON1bits.OCTSEL = SYS_CLK;// Clock Source
	OC1CON1bits.OCM = EDGE_PWM;	// PWM mode

	OC1CON2bits.OCTRIS = 0x0;	// PWM pin as output  
	
}

//----------------------------------------------
void writePWM1(unsigned int duty)
{
	OC1R  = duty;				// Duty cycle
}
